SELECT items.id, items.title,items.title_eng, items.state, items.hideprice, items.anons, items.price2rub AS price, images.path , 0 + IF(items.title LIKE "%роял%", 40, 0) + IF(items.anons LIKE "%роял%", 5, 0) + IF(items.keywords LIKE "%роял%", 20, 0) + IF(items.comment LIKE "%роял%", 1, 0) + IF(items.title LIKE "%дух%", 40, 0) + IF(items.anons LIKE "%дух%", 5, 0) + IF(items.keywords LIKE "%дух%", 20, 0) + IF(items.comment LIKE "%дух%", 1, 0) as relevance FROM `items` INNER JOIN `images` ON images.id_item=items.id WHERE ((false OR (items.title LIKE "%роял%" OR items.anons LIKE "%роял%" OR items.keywords LIKE "%роял%" OR items.comment LIKE "% роял %") OR (items.title LIKE "%дух%" OR items.anons LIKE "%дух%" OR items.keywords LIKE "%дух%" OR items.comment LIKE "% дух %")) ) AND images.visible=0 AND items.visible=1 AND items.price1_ck=0 AND items.state IN (1,2,3,4,7,9) GROUP BY items.id ORDER BY relevance DESC LIMIT 0,64